<template>
    <div>
        <div class="form-item  form-item-style1">
            <div class="label-title">
                <label>时间</label>
            </div>
            <group>
                <datetime v-model="ResumptionDate"
                          @on-change="onPullingDown"></datetime>
            </group>
        </div>
        <div class="form-item  form-item-style1 paddingR12">
            <div class="label-title">
                <label>单位名称</label>
            </div>
            <p style="display:flex;align-items: center;"
               @click="companyPropShow = true">
                <span style="color:#999;font-size:14px;">{{DepartName}}</span>
                <x-icon type="ios-arrow-right"
                        fill="#c8c8cd"
                        size="24"></x-icon>
            </p>
        </div>
        <div class="cut-off-rule"></div>
        <ul class="title-nav">
            <li>姓名</li>
            <li>已提交次数</li>
            <li>未提交次数</li>
            <li>提交率</li>
        </ul>
        <noData v-if="listAllCount == 0"></noData>
        <div class="bscroll">
            <vue-better-scroll class="wrapper"
                               ref="scroll"
                               :scrollbar="scrollbarObj"
                               :pullDownRefresh="pullDownRefreshObj"
                               :pullUpLoad="pullUpLoadObj"
                               :startY="parseInt(startY)"
                               @pullingDown="onPullingDown"
                               @pullingUp="onPullingUp">
                <div class="bscroll-container">
                    <ul ref="list"
                        class="list-content">
                        <li v-for="(item,index) in list"
                            :key="index">
                            <p>{{item.CreateUser}}</p>
                            <p>{{item.ItemCount}}</p>
                            <p>{{item.UnSubmit}}</p>
                            <p>{{item.Persent}}</p>
                        </li>
                    </ul>
                </div>
            </vue-better-scroll>
        </div>
        <companyProp :companyPropShow="companyPropShow"
                     :selectCompany="selectCompany"
                     business="GetHdProjectsAndFb"></companyProp>
        <myMenu></myMenu>
    </div>
</template>
<script>
import VueBetterScroll from 'vue2-better-scroll'
import companyProp from '@/commonComponents/companyProp'
import formatDate from '@/utils/formatDate'
import myMenu from '@/commonComponents/menu'
export default {
    name: 'statistical',
    components: {
        companyProp,
        VueBetterScroll,
        myMenu
    },
    data () {
        return {
            userInfo: {},
            // dropDown: false
            // 这个配置可以开启滚动条，默认为 false。当设置为 true 或者是一个 Object 的时候，都会开启滚动条，默认是会 fade 的
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: {
                threshold: 90,
                stop: 40
            },
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            scrollToX: 0,
            scrollToY: 0,
            scrollToTime: 700,
            companyPropShow: false,
            listAllCount: 0,
            pageIndex: 0,
            list: [],
            ResumptionDate: formatDate(),
            DepartId: '',
            DepartName: ''
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
        this.DepartId = this.userInfo.deptid
        this.DepartName = this.userInfo.deptname
    },
    mounted () {
        this.onPullingDown()
    },
    methods: {
        onPullingDown () {
            this.pageIndex = 0
            this.list = []
            this.getData()
        },
        onPullingUp () {
            this.pageIndex++
            this.getData()
        },
        getData () {
            let params = {
                'business': 'GetResumptionStatictis',
                'data': {
                    'DepartId': this.DepartId,
                    'DepartName': this.DepartName,
                    'ResumptionDate': this.ResumptionDate
                },
                'pageIndex': this.pageIndex,
                'pageSize': 10,
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params)
                .then((res) => {
                    if (res.data.code === 0) {
                        this.list = this.list.concat(res.data.data)
                        this.listCount = this.list.length
                        this.listAllCount = res.data.count
                        if (this.listCount < this.listAllCount) {
                            this.$refs[`scroll`].forceUpdate(true)
                        } else {
                            this.$refs[`scroll`].forceUpdate(false)
                        }
                    }
                }).catch((response) => {
                })
        },
        selectCompany (item) {
            this.companyPropShow = false
            this.DepartName = item.Name
            this.DepartId = item.Id
            this.onPullingDown()
        }
    }
}
</script>
<style scoped>
.paddingR12 {
    padding-right: 12px;
}
h2 {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: right;
    padding-right: 20px;
    box-sizing: border-box;
    background: #ebeef2;
}
.bscroll {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    top: 225px;
    overflow: hidden;
}
.bscroll p {
    width: 50%;
    text-align: center;
    color: #333;
}
.bscroll-container li {
    border-bottom: 1px solid #efeff4;
    padding: 18px 0 12px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.bscroll-container li h3 {
    font-size: 14px;
    color: #333;
    line-height: 20px;
    padding-bottom: 10px;
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bscroll-container li p {
    font-size: 14px;
    color: #999;
}
.title-nav {
    display: flex;
}
.title-nav li {
    width: 25%;
    line-height: 44px;
    text-align: center;
    border-bottom: 1px solid #f4f4f4;
    font-size: 14px;
    color: #333;
    border-right: 1px solid #f4f4f4;
}
.title-nav li:last-child {
    border-right: none;
}
</style>
